#include"Library.h"
void findISBN(bookNode* head, char inputISBN[MAX_ISBN])
{
	while (head)
	{
		if (strcmp(head->data.ISBN, inputISBN) == 0)
		{
			printf("ISBN:%s\t书名:%s\t\t作者:%s\t\t价格:%.2f\t库存容量:%d\n", head->data.ISBN, head->data.name,
				head->data.auth, head->data.price, head->data.inventory);
			return;
		}
		head = head->next;
	}
	printf("抱歉，未找到该书籍");
}
void findName(bookNode* head, char inputName[MAX_BOOK_NAME + 1])
{
	while (head)
	{
		if (strcmp(head->data.name, inputName) == 0)
		{
			printf("ISBN:%s\t书名:%s\t\t作者:%s\t\t价格:%.2f\t库存容量:%d\n", head->data.ISBN, head->data.name,
				head->data.auth, head->data.price, head->data.inventory);
			return;
		}
		head = head->next;
	}
	printf("抱歉，未找到该书籍");
}
void findAuth(bookNode* head, char inputAuth[MAX_AUTH_NAME + 1])
{
	while (head)
	{
		if (strcmp(head->data.auth, inputAuth) == 0)
		{
			printf("ISBN:%s\t书名:%s\t\t作者:%s\t\t价格:%.2f\t库存容量:%d\n", head->data.ISBN, head->data.name,
				head->data.auth, head->data.price, head->data.inventory);
			return;
		}
		head = head->next;
	}
	printf("抱歉，未找到该书籍");
}
void functFindBook(LibList* libList)
{
	bookNode* head = libList->head;
	printf("  查找书籍\n");
	printf("0.ISBN码查找\n");
	printf("1.书名查找\n");
	printf("2.作者查找\n");
	char choice[10];
	printf("请输入你要查找的方式:\n");
	scanf("%s", choice);
	if (choice[0] < '0' || choice[0]>'2' || strlen(choice) != 1)
	{
		printf("你是火星人吗?(任意键程序继续执行)\n");
		getch();
		return;
	}
	int select = choice[0] - '0';
	switch (select)
	{
	case 0:
		printf("请输入要查询的ISBN码:\n");
		char inputISBN[MAX_ISBN];
		scanf("%s", inputISBN);
		findISBN(head, inputISBN);
		break;
	case 1:
		printf("请输入要查询的书名:\n");
		char inputName[MAX_BOOK_NAME + 1];
		scanf("%s", inputName);
		findName(head,inputName);
		break;
	case 2:
		printf("请输入要查询的作者名:\n");
		char inputAuth[MAX_AUTH_NAME + 1];
		scanf("%s", inputAuth);
		findAuth(head, inputAuth);
		break;
	}

}
